package filter

import "github.com/project-flogo/core/data/coerce"

type Settings struct {
	Filter string `md:"filter"`
}

type Input struct {
	Data map[string]interface{} `md:"data"`
}

func (r *Input) ToMap() map[string]interface{} {
	return map[string]interface{}{
		"data": r.Data,
	}
}

func (r *Input) FromMap(values map[string]interface{}) error {
	data, err := coerce.ToObject(values["data"])
	if err != nil {
		return err
	}
	r.Data = data
	return nil
}

type Output struct {
	Data map[string]interface{} `md:"data"`
}

func (r *Output) ToMap() map[string]interface{} {
	return map[string]interface{}{
		"data": r.Data,
	}
}

func (r *Output) FromMap(values map[string]interface{}) error {
	data, err := coerce.ToObject(values["data"])
	if err != nil {
		return err
	}
	r.Data = data
	return nil
}
